#pragma once

#include "ValuePin.h"

#include "ValueSpecification.h"

namespace uml {

ValuePin::ValuePin(const QString& umlType)
    : InputPin(umlType) {}

void ValuePin::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    InputPin::fromJson(json, errorList);
    value_ = JsonSerializable::create<ValueSpecification>(json.value("value"), errorList);

}

void ValuePin::toJson(QJsonObject& json) {
    InputPin::toJson(json);
    if (value_) {
        QJsonObject value_json;
        value_->toJson(value_json);
        json.insert("value", value_json);
    }
}

/// <summary>
/// value getter
/// The ValueSpecification that is evaluated to obtain the value that the ValuePin
/// will provide.
/// </summary>
shared_ptr<ValueSpecification> ValuePin::value() const {
    return value_;
}

/// <summary>
/// value setter
/// The ValueSpecification that is evaluated to obtain the value that the ValuePin
/// will provide.
/// </summary>
void ValuePin::setValue(shared_ptr<ValueSpecification> value) {
    value_ = value;
}

} // namespace uml
